import React from 'react'
import { Navigate } from 'react-router-dom'
import type { RouteObject } from 'react-router-dom'
import { lazy } from 'react'

// 辅助函数，用于创建懒加载组件的路由元素
const lazyLoadRouteElement = (
  importFunction: () => Promise<{ default: React.ComponentType<any> }>
) => {
  const LazyComponent = lazy(importFunction)
  return <LazyComponent />
}

const Download = lazy(() => import('@/views/Download'))
const Mine = lazy(() => import('@/views/Mine'))
const Focus = lazy(() => import('@/views/Focus'))

const routes: RouteObject[] = [
  {
    path: '/',
    element: <Navigate to="/discover" />
  },
  {
    path: '/discover',
    element: lazyLoadRouteElement(() => import('@/views/DisCover')),
    children: [
      {
        path: '/discover',
        element: <Navigate to="/discover/recommend" />
      },
      {
        path: '/discover/album',
        element: lazyLoadRouteElement(
          () => import('@/views/DisCover/c-views/album')
        )
      },
      {
        path: '/discover/artist',
        element: lazyLoadRouteElement(
          () => import('@/views/DisCover/c-views/artist')
        )
      },
      {
        path: '/discover/diRadion',
        element: lazyLoadRouteElement(
          () => import('@/views/DisCover/c-views/diradio')
        )
      },
      {
        path: '/discover/songs',
        element: lazyLoadRouteElement(
          () => import('@/views/DisCover/c-views/songs')
        )
      },
      {
        path: '/discover/recommend',
        element: lazyLoadRouteElement(
          () => import('@/views/DisCover/c-views/recommend')
        )
      },
      {
        path: '/discover/ranking',
        element: lazyLoadRouteElement(
          () => import('@/views/DisCover/c-views/ranking')
        )
      }
    ]
  },
  {
    path: '/download',
    element: <Download />
  },
  {
    path: '/mine',
    element: <Mine />
  },
  {
    path: '/focus',
    element: <Focus />
  }
]

export default routes
